{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "397a3bae",
   "metadata": {},
   "source": [
    "# python学习记录"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f43ba3d",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "## 1随机函数\n",
    "## 2时间函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2754497",
   "metadata": {},
   "source": [
    "## 1.随机函数\n",
    "> 1.random.random():生成随机数，0-1之间\n",
    "> 2.random.randint():生成随机数\n",
    ">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "24206ac9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e5bf9f87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module random:\n",
      "\n",
      "NAME\n",
      "    random - Random variable generators.\n",
      "\n",
      "MODULE REFERENCE\n",
      "    https://docs.python.org/3.9/library/random\n",
      "    \n",
      "    The following documentation is automatically generated from the Python\n",
      "    source files.  It may be incomplete, incorrect or include features that\n",
      "    are considered implementation detail and may vary between Python\n",
      "    implementations.  When in doubt, consult the module reference at the\n",
      "    location listed above.\n",
      "\n",
      "DESCRIPTION\n",
      "        bytes\n",
      "        -----\n",
      "               uniform bytes (values between 0 and 255)\n",
      "    \n",
      "        integers\n",
      "        --------\n",
      "               uniform within range\n",
      "    \n",
      "        sequences\n",
      "        ---------\n",
      "               pick random element\n",
      "               pick random sample\n",
      "               pick weighted random sample\n",
      "               generate random permutation\n",
      "    \n",
      "        distributions on the real line:\n",
      "        ------------------------------\n",
      "               uniform\n",
      "               triangular\n",
      "               normal (Gaussian)\n",
      "               lognormal\n",
      "               negative exponential\n",
      "               gamma\n",
      "               beta\n",
      "               pareto\n",
      "               Weibull\n",
      "    \n",
      "        distributions on the circle (angles 0 to 2pi)\n",
      "        ---------------------------------------------\n",
      "               circular uniform\n",
      "               von Mises\n",
      "    \n",
      "    General notes on the underlying Mersenne Twister core generator:\n",
      "    \n",
      "    * The period is 2**19937-1.\n",
      "    * It is one of the most extensively tested generators in existence.\n",
      "    * The random() method is implemented in C, executes in a single Python step,\n",
      "      and is, therefore, threadsafe.\n",
      "\n",
      "CLASSES\n",
      "    _random.Random(builtins.object)\n",
      "        Random\n",
      "            SystemRandom\n",
      "    \n",
      "    class Random(_random.Random)\n",
      "     |  Random(x=None)\n",
      "     |  \n",
      "     |  Random number generator base class used by bound module functions.\n",
      "     |  \n",
      "     |  Used to instantiate instances of Random to get generators that don't\n",
      "     |  share state.\n",
      "     |  \n",
      "     |  Class Random can also be subclassed if you want to use a different basic\n",
      "     |  generator of your own devising: in that case, override the following\n",
      "     |  methods:  random(), seed(), getstate(), and setstate().\n",
      "     |  Optionally, implement a getrandbits() method so that randrange()\n",
      "     |  can cover arbitrarily large ranges.\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      Random\n",
      "     |      _random.Random\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  __getstate__(self)\n",
      "     |      # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
      "     |      # longer called; we leave it here because it has been here since random was\n",
      "     |      # rewritten back in 2001 and why risk breaking something.\n",
      "     |  \n",
      "     |  __init__(self, x=None)\n",
      "     |      Initialize an instance.\n",
      "     |      \n",
      "     |      Optional argument x controls seeding, as for Random.seed().\n",
      "     |  \n",
      "     |  __reduce__(self)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __setstate__(self, state)\n",
      "     |  \n",
      "     |  betavariate(self, alpha, beta)\n",
      "     |      Beta distribution.\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      Returned values range between 0 and 1.\n",
      "     |  \n",
      "     |  choice(self, seq)\n",
      "     |      Choose a random element from a non-empty sequence.\n",
      "     |  \n",
      "     |  choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
      "     |      Return a k sized list of population elements chosen with replacement.\n",
      "     |      \n",
      "     |      If the relative weights or cumulative weights are not specified,\n",
      "     |      the selections are made with equal probability.\n",
      "     |  \n",
      "     |  expovariate(self, lambd)\n",
      "     |      Exponential distribution.\n",
      "     |      \n",
      "     |      lambd is 1.0 divided by the desired mean.  It should be\n",
      "     |      nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "     |      a reserved word in Python.)  Returned values range from 0 to\n",
      "     |      positive infinity if lambd is positive, and from negative\n",
      "     |      infinity to 0 if lambd is negative.\n",
      "     |  \n",
      "     |  gammavariate(self, alpha, beta)\n",
      "     |      Gamma distribution.  Not the gamma function!\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      \n",
      "     |      The probability distribution function is:\n",
      "     |      \n",
      "     |                  x ** (alpha - 1) * math.exp(-x / beta)\n",
      "     |        pdf(x) =  --------------------------------------\n",
      "     |                    math.gamma(alpha) * beta ** alpha\n",
      "     |  \n",
      "     |  gauss(self, mu, sigma)\n",
      "     |      Gaussian distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.  This is\n",
      "     |      slightly faster than the normalvariate() function.\n",
      "     |      \n",
      "     |      Not thread-safe without a lock around calls.\n",
      "     |  \n",
      "     |  getstate(self)\n",
      "     |      Return internal state; can be passed to setstate() later.\n",
      "     |  \n",
      "     |  lognormvariate(self, mu, sigma)\n",
      "     |      Log normal distribution.\n",
      "     |      \n",
      "     |      If you take the natural logarithm of this distribution, you'll get a\n",
      "     |      normal distribution with mean mu and standard deviation sigma.\n",
      "     |      mu can have any value, and sigma must be greater than zero.\n",
      "     |  \n",
      "     |  normalvariate(self, mu, sigma)\n",
      "     |      Normal distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.\n",
      "     |  \n",
      "     |  paretovariate(self, alpha)\n",
      "     |      Pareto distribution.  alpha is the shape parameter.\n",
      "     |  \n",
      "     |  randbytes(self, n)\n",
      "     |      Generate n random bytes.\n",
      "     |  \n",
      "     |  randint(self, a, b)\n",
      "     |      Return random integer in range [a, b], including both end points.\n",
      "     |  \n",
      "     |  randrange(self, start, stop=None, step=1)\n",
      "     |      Choose a random item from range(start, stop[, step]).\n",
      "     |      \n",
      "     |      This fixes the problem with randint() which includes the\n",
      "     |      endpoint; in Python this is usually not what you want.\n",
      "     |  \n",
      "     |  sample(self, population, k, *, counts=None)\n",
      "     |      Chooses k unique random elements from a population sequence or set.\n",
      "     |      \n",
      "     |      Returns a new list containing elements from the population while\n",
      "     |      leaving the original population unchanged.  The resulting list is\n",
      "     |      in selection order so that all sub-slices will also be valid random\n",
      "     |      samples.  This allows raffle winners (the sample) to be partitioned\n",
      "     |      into grand prize and second place winners (the subslices).\n",
      "     |      \n",
      "     |      Members of the population need not be hashable or unique.  If the\n",
      "     |      population contains repeats, then each occurrence is a possible\n",
      "     |      selection in the sample.\n",
      "     |      \n",
      "     |      Repeated elements can be specified one at a time or with the optional\n",
      "     |      counts parameter.  For example:\n",
      "     |      \n",
      "     |          sample(['red', 'blue'], counts=[4, 2], k=5)\n",
      "     |      \n",
      "     |      is equivalent to:\n",
      "     |      \n",
      "     |          sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)\n",
      "     |      \n",
      "     |      To choose a sample from a range of integers, use range() for the\n",
      "     |      population argument.  This is especially fast and space efficient\n",
      "     |      for sampling from a large population:\n",
      "     |      \n",
      "     |          sample(range(10000000), 60)\n",
      "     |  \n",
      "     |  seed(self, a=None, version=2)\n",
      "     |      Initialize internal state from a seed.\n",
      "     |      \n",
      "     |      The only supported seed types are None, int, float,\n",
      "     |      str, bytes, and bytearray.\n",
      "     |      \n",
      "     |      None or no argument seeds from current time or from an operating\n",
      "     |      system specific randomness source if available.\n",
      "     |      \n",
      "     |      If *a* is an int, all bits are used.\n",
      "     |      \n",
      "     |      For version 2 (the default), all of the bits are used if *a* is a str,\n",
      "     |      bytes, or bytearray.  For version 1 (provided for reproducing random\n",
      "     |      sequences from older versions of Python), the algorithm for str and\n",
      "     |      bytes generates a narrower range of seeds.\n",
      "     |  \n",
      "     |  setstate(self, state)\n",
      "     |      Restore internal state from object returned by getstate().\n",
      "     |  \n",
      "     |  shuffle(self, x, random=None)\n",
      "     |      Shuffle list x in place, and return None.\n",
      "     |      \n",
      "     |      Optional argument random is a 0-argument function returning a\n",
      "     |      random float in [0.0, 1.0); if it is the default None, the\n",
      "     |      standard random.random will be used.\n",
      "     |  \n",
      "     |  triangular(self, low=0.0, high=1.0, mode=None)\n",
      "     |      Triangular distribution.\n",
      "     |      \n",
      "     |      Continuous distribution bounded by given lower and upper limits,\n",
      "     |      and having a given mode value in-between.\n",
      "     |      \n",
      "     |      http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "     |  \n",
      "     |  uniform(self, a, b)\n",
      "     |      Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "     |  \n",
      "     |  vonmisesvariate(self, mu, kappa)\n",
      "     |      Circular data distribution.\n",
      "     |      \n",
      "     |      mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "     |      kappa is the concentration parameter, which must be greater than or\n",
      "     |      equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "     |      to a uniform random angle over the range 0 to 2*pi.\n",
      "     |  \n",
      "     |  weibullvariate(self, alpha, beta)\n",
      "     |      Weibull distribution.\n",
      "     |      \n",
      "     |      alpha is the scale parameter and beta is the shape parameter.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Class methods defined here:\n",
      "     |  \n",
      "     |  __init_subclass__(**kwargs) from builtins.type\n",
      "     |      Control how subclasses generate random integers.\n",
      "     |      \n",
      "     |      The algorithm a subclass can use depends on the random() and/or\n",
      "     |      getrandbits() implementation available to it and determines\n",
      "     |      whether it can generate random integers from arbitrarily large\n",
      "     |      ranges.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors defined here:\n",
      "     |  \n",
      "     |  __dict__\n",
      "     |      dictionary for instance variables (if defined)\n",
      "     |  \n",
      "     |  __weakref__\n",
      "     |      list of weak references to the object (if defined)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes defined here:\n",
      "     |  \n",
      "     |  VERSION = 3\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  getrandbits(self, k, /)\n",
      "     |      getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "     |  \n",
      "     |  random(self, /)\n",
      "     |      random() -> x in the interval [0, 1).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "    \n",
      "    class SystemRandom(Random)\n",
      "     |  SystemRandom(x=None)\n",
      "     |  \n",
      "     |  Alternate random number generator using sources provided\n",
      "     |  by the operating system (such as /dev/urandom on Unix or\n",
      "     |  CryptGenRandom on Windows).\n",
      "     |  \n",
      "     |   Not available on all systems (see os.urandom() for details).\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      SystemRandom\n",
      "     |      Random\n",
      "     |      _random.Random\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  getrandbits(self, k)\n",
      "     |      getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "     |  \n",
      "     |  getstate = _notimplemented(self, *args, **kwds)\n",
      "     |  \n",
      "     |  randbytes(self, n)\n",
      "     |      Generate n random bytes.\n",
      "     |  \n",
      "     |  random(self)\n",
      "     |      Get the next random number in the range [0.0, 1.0).\n",
      "     |  \n",
      "     |  seed(self, *args, **kwds)\n",
      "     |      Stub method.  Not used for a system random number generator.\n",
      "     |  \n",
      "     |  setstate = _notimplemented(self, *args, **kwds)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from Random:\n",
      "     |  \n",
      "     |  __getstate__(self)\n",
      "     |      # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
      "     |      # longer called; we leave it here because it has been here since random was\n",
      "     |      # rewritten back in 2001 and why risk breaking something.\n",
      "     |  \n",
      "     |  __init__(self, x=None)\n",
      "     |      Initialize an instance.\n",
      "     |      \n",
      "     |      Optional argument x controls seeding, as for Random.seed().\n",
      "     |  \n",
      "     |  __reduce__(self)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __setstate__(self, state)\n",
      "     |  \n",
      "     |  betavariate(self, alpha, beta)\n",
      "     |      Beta distribution.\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      Returned values range between 0 and 1.\n",
      "     |  \n",
      "     |  choice(self, seq)\n",
      "     |      Choose a random element from a non-empty sequence.\n",
      "     |  \n",
      "     |  choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
      "     |      Return a k sized list of population elements chosen with replacement.\n",
      "     |      \n",
      "     |      If the relative weights or cumulative weights are not specified,\n",
      "     |      the selections are made with equal probability.\n",
      "     |  \n",
      "     |  expovariate(self, lambd)\n",
      "     |      Exponential distribution.\n",
      "     |      \n",
      "     |      lambd is 1.0 divided by the desired mean.  It should be\n",
      "     |      nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "     |      a reserved word in Python.)  Returned values range from 0 to\n",
      "     |      positive infinity if lambd is positive, and from negative\n",
      "     |      infinity to 0 if lambd is negative.\n",
      "     |  \n",
      "     |  gammavariate(self, alpha, beta)\n",
      "     |      Gamma distribution.  Not the gamma function!\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      \n",
      "     |      The probability distribution function is:\n",
      "     |      \n",
      "     |                  x ** (alpha - 1) * math.exp(-x / beta)\n",
      "     |        pdf(x) =  --------------------------------------\n",
      "     |                    math.gamma(alpha) * beta ** alpha\n",
      "     |  \n",
      "     |  gauss(self, mu, sigma)\n",
      "     |      Gaussian distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.  This is\n",
      "     |      slightly faster than the normalvariate() function.\n",
      "     |      \n",
      "     |      Not thread-safe without a lock around calls.\n",
      "     |  \n",
      "     |  lognormvariate(self, mu, sigma)\n",
      "     |      Log normal distribution.\n",
      "     |      \n",
      "     |      If you take the natural logarithm of this distribution, you'll get a\n",
      "     |      normal distribution with mean mu and standard deviation sigma.\n",
      "     |      mu can have any value, and sigma must be greater than zero.\n",
      "     |  \n",
      "     |  normalvariate(self, mu, sigma)\n",
      "     |      Normal distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.\n",
      "     |  \n",
      "     |  paretovariate(self, alpha)\n",
      "     |      Pareto distribution.  alpha is the shape parameter.\n",
      "     |  \n",
      "     |  randint(self, a, b)\n",
      "     |      Return random integer in range [a, b], including both end points.\n",
      "     |  \n",
      "     |  randrange(self, start, stop=None, step=1)\n",
      "     |      Choose a random item from range(start, stop[, step]).\n",
      "     |      \n",
      "     |      This fixes the problem with randint() which includes the\n",
      "     |      endpoint; in Python this is usually not what you want.\n",
      "     |  \n",
      "     |  sample(self, population, k, *, counts=None)\n",
      "     |      Chooses k unique random elements from a population sequence or set.\n",
      "     |      \n",
      "     |      Returns a new list containing elements from the population while\n",
      "     |      leaving the original population unchanged.  The resulting list is\n",
      "     |      in selection order so that all sub-slices will also be valid random\n",
      "     |      samples.  This allows raffle winners (the sample) to be partitioned\n",
      "     |      into grand prize and second place winners (the subslices).\n",
      "     |      \n",
      "     |      Members of the population need not be hashable or unique.  If the\n",
      "     |      population contains repeats, then each occurrence is a possible\n",
      "     |      selection in the sample.\n",
      "     |      \n",
      "     |      Repeated elements can be specified one at a time or with the optional\n",
      "     |      counts parameter.  For example:\n",
      "     |      \n",
      "     |          sample(['red', 'blue'], counts=[4, 2], k=5)\n",
      "     |      \n",
      "     |      is equivalent to:\n",
      "     |      \n",
      "     |          sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)\n",
      "     |      \n",
      "     |      To choose a sample from a range of integers, use range() for the\n",
      "     |      population argument.  This is especially fast and space efficient\n",
      "     |      for sampling from a large population:\n",
      "     |      \n",
      "     |          sample(range(10000000), 60)\n",
      "     |  \n",
      "     |  shuffle(self, x, random=None)\n",
      "     |      Shuffle list x in place, and return None.\n",
      "     |      \n",
      "     |      Optional argument random is a 0-argument function returning a\n",
      "     |      random float in [0.0, 1.0); if it is the default None, the\n",
      "     |      standard random.random will be used.\n",
      "     |  \n",
      "     |  triangular(self, low=0.0, high=1.0, mode=None)\n",
      "     |      Triangular distribution.\n",
      "     |      \n",
      "     |      Continuous distribution bounded by given lower and upper limits,\n",
      "     |      and having a given mode value in-between.\n",
      "     |      \n",
      "     |      http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "     |  \n",
      "     |  uniform(self, a, b)\n",
      "     |      Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "     |  \n",
      "     |  vonmisesvariate(self, mu, kappa)\n",
      "     |      Circular data distribution.\n",
      "     |      \n",
      "     |      mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "     |      kappa is the concentration parameter, which must be greater than or\n",
      "     |      equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "     |      to a uniform random angle over the range 0 to 2*pi.\n",
      "     |  \n",
      "     |  weibullvariate(self, alpha, beta)\n",
      "     |      Weibull distribution.\n",
      "     |      \n",
      "     |      alpha is the scale parameter and beta is the shape parameter.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Class methods inherited from Random:\n",
      "     |  \n",
      "     |  __init_subclass__(**kwargs) from builtins.type\n",
      "     |      Control how subclasses generate random integers.\n",
      "     |      \n",
      "     |      The algorithm a subclass can use depends on the random() and/or\n",
      "     |      getrandbits() implementation available to it and determines\n",
      "     |      whether it can generate random integers from arbitrarily large\n",
      "     |      ranges.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors inherited from Random:\n",
      "     |  \n",
      "     |  __dict__\n",
      "     |      dictionary for instance variables (if defined)\n",
      "     |  \n",
      "     |  __weakref__\n",
      "     |      list of weak references to the object (if defined)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes inherited from Random:\n",
      "     |  \n",
      "     |  VERSION = 3\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n",
      "FUNCTIONS\n",
      "    betavariate(alpha, beta) method of Random instance\n",
      "        Beta distribution.\n",
      "        \n",
      "        Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "        Returned values range between 0 and 1.\n",
      "    \n",
      "    choice(seq) method of Random instance\n",
      "        Choose a random element from a non-empty sequence.\n",
      "    \n",
      "    choices(population, weights=None, *, cum_weights=None, k=1) method of Random instance\n",
      "        Return a k sized list of population elements chosen with replacement.\n",
      "        \n",
      "        If the relative weights or cumulative weights are not specified,\n",
      "        the selections are made with equal probability.\n",
      "    \n",
      "    expovariate(lambd) method of Random instance\n",
      "        Exponential distribution.\n",
      "        \n",
      "        lambd is 1.0 divided by the desired mean.  It should be\n",
      "        nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "        a reserved word in Python.)  Returned values range from 0 to\n",
      "        positive infinity if lambd is positive, and from negative\n",
      "        infinity to 0 if lambd is negative.\n",
      "    \n",
      "    gammavariate(alpha, beta) method of Random instance\n",
      "        Gamma distribution.  Not the gamma function!\n",
      "        \n",
      "        Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "        \n",
      "        The probability distribution function is:\n",
      "        \n",
      "                    x ** (alpha - 1) * math.exp(-x / beta)\n",
      "          pdf(x) =  --------------------------------------\n",
      "                      math.gamma(alpha) * beta ** alpha\n",
      "    \n",
      "    gauss(mu, sigma) method of Random instance\n",
      "        Gaussian distribution.\n",
      "        \n",
      "        mu is the mean, and sigma is the standard deviation.  This is\n",
      "        slightly faster than the normalvariate() function.\n",
      "        \n",
      "        Not thread-safe without a lock around calls.\n",
      "    \n",
      "    getrandbits(k, /) method of Random instance\n",
      "        getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "    \n",
      "    getstate() method of Random instance\n",
      "        Return internal state; can be passed to setstate() later.\n",
      "    \n",
      "    lognormvariate(mu, sigma) method of Random instance\n",
      "        Log normal distribution.\n",
      "        \n",
      "        If you take the natural logarithm of this distribution, you'll get a\n",
      "        normal distribution with mean mu and standard deviation sigma.\n",
      "        mu can have any value, and sigma must be greater than zero.\n",
      "    \n",
      "    normalvariate(mu, sigma) method of Random instance\n",
      "        Normal distribution.\n",
      "        \n",
      "        mu is the mean, and sigma is the standard deviation.\n",
      "    \n",
      "    paretovariate(alpha) method of Random instance\n",
      "        Pareto distribution.  alpha is the shape parameter.\n",
      "    \n",
      "    randbytes(n) method of Random instance\n",
      "        Generate n random bytes.\n",
      "    \n",
      "    randint(a, b) method of Random instance\n",
      "        Return random integer in range [a, b], including both end points.\n",
      "    \n",
      "    random() method of Random instance\n",
      "        random() -> x in the interval [0, 1).\n",
      "    \n",
      "    randrange(start, stop=None, step=1) method of Random instance\n",
      "        Choose a random item from range(start, stop[, step]).\n",
      "        \n",
      "        This fixes the problem with randint() which includes the\n",
      "        endpoint; in Python this is usually not what you want.\n",
      "    \n",
      "    sample(population, k, *, counts=None) method of Random instance\n",
      "        Chooses k unique random elements from a population sequence or set.\n",
      "        \n",
      "        Returns a new list containing elements from the population while\n",
      "        leaving the original population unchanged.  The resulting list is\n",
      "        in selection order so that all sub-slices will also be valid random\n",
      "        samples.  This allows raffle winners (the sample) to be partitioned\n",
      "        into grand prize and second place winners (the subslices).\n",
      "        \n",
      "        Members of the population need not be hashable or unique.  If the\n",
      "        population contains repeats, then each occurrence is a possible\n",
      "        selection in the sample.\n",
      "        \n",
      "        Repeated elements can be specified one at a time or with the optional\n",
      "        counts parameter.  For example:\n",
      "        \n",
      "            sample(['red', 'blue'], counts=[4, 2], k=5)\n",
      "        \n",
      "        is equivalent to:\n",
      "        \n",
      "            sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)\n",
      "        \n",
      "        To choose a sample from a range of integers, use range() for the\n",
      "        population argument.  This is especially fast and space efficient\n",
      "        for sampling from a large population:\n",
      "        \n",
      "            sample(range(10000000), 60)\n",
      "    \n",
      "    seed(a=None, version=2) method of Random instance\n",
      "        Initialize internal state from a seed.\n",
      "        \n",
      "        The only supported seed types are None, int, float,\n",
      "        str, bytes, and bytearray.\n",
      "        \n",
      "        None or no argument seeds from current time or from an operating\n",
      "        system specific randomness source if available.\n",
      "        \n",
      "        If *a* is an int, all bits are used.\n",
      "        \n",
      "        For version 2 (the default), all of the bits are used if *a* is a str,\n",
      "        bytes, or bytearray.  For version 1 (provided for reproducing random\n",
      "        sequences from older versions of Python), the algorithm for str and\n",
      "        bytes generates a narrower range of seeds.\n",
      "    \n",
      "    setstate(state) method of Random instance\n",
      "        Restore internal state from object returned by getstate().\n",
      "    \n",
      "    shuffle(x, random=None) method of Random instance\n",
      "        Shuffle list x in place, and return None.\n",
      "        \n",
      "        Optional argument random is a 0-argument function returning a\n",
      "        random float in [0.0, 1.0); if it is the default None, the\n",
      "        standard random.random will be used.\n",
      "    \n",
      "    triangular(low=0.0, high=1.0, mode=None) method of Random instance\n",
      "        Triangular distribution.\n",
      "        \n",
      "        Continuous distribution bounded by given lower and upper limits,\n",
      "        and having a given mode value in-between.\n",
      "        \n",
      "        http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "    \n",
      "    uniform(a, b) method of Random instance\n",
      "        Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "    \n",
      "    vonmisesvariate(mu, kappa) method of Random instance\n",
      "        Circular data distribution.\n",
      "        \n",
      "        mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "        kappa is the concentration parameter, which must be greater than or\n",
      "        equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "        to a uniform random angle over the range 0 to 2*pi.\n",
      "    \n",
      "    weibullvariate(alpha, beta) method of Random instance\n",
      "        Weibull distribution.\n",
      "        \n",
      "        alpha is the scale parameter and beta is the shape parameter.\n",
      "\n",
      "DATA\n",
      "    __all__ = ['Random', 'SystemRandom', 'betavariate', 'choice', 'choices...\n",
      "\n",
      "FILE\n",
      "    d:\\python\\anaconda3\\lib\\random.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "57fa660d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.13197790864243375"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "aaceefe1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f9e15338",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "1\n",
      "3\n",
      "6\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "# 大话骰\n",
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4823a98c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.choice()\n",
    "random.choice([\"小红\",\"李华\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "b3116667",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "75\n",
      "20\n",
      "96\n",
      "93\n",
      "49\n",
      "60\n"
     ]
    }
   ],
   "source": [
    "# 通过随机值，大概去判断一下彩票的中奖概率\n",
    "# [12,34,56,10,22,12]\n",
    "for i in range(6):\n",
    "    print(random.randint(0,99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "095ec6c5",
   "metadata": {},
   "source": [
    "## 2时间函数\n",
    "### 时间延迟函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "5e7d1784",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "76acf34c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=9, tm_mday=26, tm_hour=10, tm_min=28, tm_sec=19, tm_wday=0, tm_yday=269, tm_isdst=0)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "71188ac6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "914d8e45",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好\n"
     ]
    }
   ],
   "source": [
    "time.sleep(2)\n",
    "print(\"你好\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "76920853",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aaa\n",
      "bbb 20 ccc\n",
      "ccc\n"
     ]
    }
   ],
   "source": [
    "# 浏览抓取网页数据，模拟人的行为，让机器慢下来，没执行一次休息3秒钟\n",
    "# 进阶：随机产生一个数(3,50),让机器随机停留\n",
    "if i in range (5):\n",
    "    print(\"aaa\")\n",
    "    wait_time = random.randint(3,20)\n",
    "    print(\"bbb\",wait_time,\"ccc\")\n",
    "    time.sleep(wait_time)\n",
    "    print(\"ccc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "fe827ae4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 课本p33，p44"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9341647e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute\n",
      "Not an odd minute\n",
      "Not an odd minute\n",
      "This minute seems a little odd.\n",
      "Not an odd minute\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds =[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_minute = datetime.today().minute\n",
    "    if right_this_minute in odds:\n",
    "        print(\"This minute seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd minute\")\n",
    "    wait_time = random.randint(1,60)\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8b82c806",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles of beer on the wall.\n",
      "99 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "98 bottles of beer on the wall.\n",
      "98 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "97 bottles of beer on the wall.\n",
      "97 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "96 bottles of beer on the wall.\n",
      "96 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "95 bottles of beer on the wall.\n",
      "95 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "94 bottles of beer on the wall.\n",
      "94 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "93 bottles of beer on the wall.\n",
      "93 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "92 bottles of beer on the wall.\n",
      "92 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "91 bottles of beer on the wall.\n",
      "91 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "90 bottles of beer on the wall.\n",
      "90 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "89 bottles of beer on the wall.\n",
      "89 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "88 bottles of beer on the wall.\n",
      "88 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "87 bottles of beer on the wall.\n",
      "87 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "86 bottles of beer on the wall.\n",
      "86 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "85 bottles of beer on the wall.\n",
      "85 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "84 bottles of beer on the wall.\n",
      "84 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "83 bottles of beer on the wall.\n",
      "83 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "82 bottles of beer on the wall.\n",
      "82 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "81 bottles of beer on the wall.\n",
      "81 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "80 bottles of beer on the wall.\n",
      "80 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "79 bottles of beer on the wall.\n",
      "79 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "78 bottles of beer on the wall.\n",
      "78 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "77 bottles of beer on the wall.\n",
      "77 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "76 bottles of beer on the wall.\n",
      "76 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "75 bottles of beer on the wall.\n",
      "75 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "74 bottles of beer on the wall.\n",
      "74 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "73 bottles of beer on the wall.\n",
      "73 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "72 bottles of beer on the wall.\n",
      "72 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "71 bottles of beer on the wall.\n",
      "71 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "70 bottles of beer on the wall.\n",
      "70 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "69 bottles of beer on the wall.\n",
      "69 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "68 bottles of beer on the wall.\n",
      "68 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "67 bottles of beer on the wall.\n",
      "67 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "66 bottles of beer on the wall.\n",
      "66 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "65 bottles of beer on the wall.\n",
      "65 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "64 bottles of beer on the wall.\n",
      "64 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "63 bottles of beer on the wall.\n",
      "63 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "62 bottles of beer on the wall.\n",
      "62 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "61 bottles of beer on the wall.\n",
      "61 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "60 bottles of beer on the wall.\n",
      "60 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "59 bottles of beer on the wall.\n",
      "59 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "58 bottles of beer on the wall.\n",
      "58 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "57 bottles of beer on the wall.\n",
      "57 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "56 bottles of beer on the wall.\n",
      "56 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "55 bottles of beer on the wall.\n",
      "55 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "54 bottles of beer on the wall.\n",
      "54 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "53 bottles of beer on the wall.\n",
      "53 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "52 bottles of beer on the wall.\n",
      "52 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "51 bottles of beer on the wall.\n",
      "51 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "50 bottles of beer on the wall.\n",
      "50 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "49 bottles of beer on the wall.\n",
      "49 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "48 bottles of beer on the wall.\n",
      "48 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "47 bottles of beer on the wall.\n",
      "47 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "46 bottles of beer on the wall.\n",
      "46 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "45 bottles of beer on the wall.\n",
      "45 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "44 bottles of beer on the wall.\n",
      "44 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "43 bottles of beer on the wall.\n",
      "43 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "42 bottles of beer on the wall.\n",
      "42 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "41 bottles of beer on the wall.\n",
      "41 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "40 bottles of beer on the wall.\n",
      "40 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "39 bottles of beer on the wall.\n",
      "39 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "38 bottles of beer on the wall.\n",
      "38 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "37 bottles of beer on the wall.\n",
      "37 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "36 bottles of beer on the wall.\n",
      "36 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "35 bottles of beer on the wall.\n",
      "35 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "34 bottles of beer on the wall.\n",
      "34 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "33 bottles of beer on the wall.\n",
      "33 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "32 bottles of beer on the wall.\n",
      "32 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "31 bottles of beer on the wall.\n",
      "31 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "30 bottles of beer on the wall.\n",
      "30 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "29 bottles of beer on the wall.\n",
      "29 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "28 bottles of beer on the wall.\n",
      "28 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "27 bottles of beer on the wall.\n",
      "27 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "26 bottles of beer on the wall.\n",
      "26 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "25 bottles of beer on the wall.\n",
      "25 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "24 bottles of beer on the wall.\n",
      "24 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "23 bottles of beer on the wall.\n",
      "23 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "22 bottles of beer on the wall.\n",
      "22 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "21 bottles of beer on the wall.\n",
      "21 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "20 bottles of beer on the wall.\n",
      "20 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "19 bottles of beer on the wall.\n",
      "19 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "18 bottles of beer on the wall.\n",
      "18 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "17 bottles of beer on the wall.\n",
      "17 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "16 bottles of beer on the wall.\n",
      "16 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "15 bottles of beer on the wall.\n",
      "15 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "14 bottles of beer on the wall.\n",
      "14 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "13 bottles of beer on the wall.\n",
      "13 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "12 bottles of beer on the wall.\n",
      "12 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "11 bottles of beer on the wall.\n",
      "11 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "10 bottles of beer on the wall.\n",
      "10 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "9 bottles of beer on the wall.\n",
      "9 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "8 bottles of beer on the wall.\n",
      "8 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "7 bottles of beer on the wall.\n",
      "7 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "6 bottles of beer on the wall.\n",
      "6 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "5 bottles of beer on the wall.\n",
      "5 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "1 bottles of beer on the wall.\n",
      "1 bottles of beer\n",
      "take one down.\n",
      "pass it around.\n",
      "no more bottles of beer on the wall\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 课本p44\n",
    "word = \"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num, word, \"of beer on the wall.\")\n",
    "    print(beer_num, word, \"of beer\")\n",
    "    print(\"take one down.\")\n",
    "    print(\"pass it around.\")\n",
    "if beer_num ==1:\n",
    "    print(\"no more bottles of beer on the wall\")\n",
    "else:\n",
    "    new_num = beer_num - 1\n",
    "    if new_num == 1:\n",
    "        word = \"bottle\"\n",
    "    print(new_num, word, \"of beer on the wall.\")\n",
    "print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f86a966d",
   "metadata": {},
   "source": [
    "## 有序的数据结构()\n",
    " >  1.数值\n",
    " >  2.字符串\n",
    " >  3.列表，元组，字典，集合（期中考核）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acaedd04",
   "metadata": {},
   "source": [
    "### 3.1数值的基本运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "72d35057",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5eea3aea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Operation</th>\n",
       "      <th>Result</th>\n",
       "      <th>Notes</th>\n",
       "      <th>Full documentation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>x + y</td>\n",
       "      <td>sum of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>x - y</td>\n",
       "      <td>difference of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>x * y</td>\n",
       "      <td>product of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>x / y</td>\n",
       "      <td>quotient of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>x // y</td>\n",
       "      <td>floored quotient of x and y</td>\n",
       "      <td>(1)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>x % y</td>\n",
       "      <td>remainder of x / y</td>\n",
       "      <td>(2)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-x</td>\n",
       "      <td>x negated</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>+x</td>\n",
       "      <td>x unchanged</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>abs(x)</td>\n",
       "      <td>absolute value or magnitude of x</td>\n",
       "      <td>NaN</td>\n",
       "      <td>abs()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>int(x)</td>\n",
       "      <td>x converted to integer</td>\n",
       "      <td>(3)(6)</td>\n",
       "      <td>int()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>float(x)</td>\n",
       "      <td>x converted to floating point</td>\n",
       "      <td>(4)(6)</td>\n",
       "      <td>float()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>complex(re, im)</td>\n",
       "      <td>a complex number with real part re, imaginary ...</td>\n",
       "      <td>(6)</td>\n",
       "      <td>complex()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>c.conjugate()</td>\n",
       "      <td>conjugate of the complex number c</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>divmod(x, y)</td>\n",
       "      <td>the pair (x // y, x % y)</td>\n",
       "      <td>(2)</td>\n",
       "      <td>divmod()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>pow(x, y)</td>\n",
       "      <td>x to the power y</td>\n",
       "      <td>(5)</td>\n",
       "      <td>pow()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>x ** y</td>\n",
       "      <td>x to the power y</td>\n",
       "      <td>(5)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Operation                                             Result  \\\n",
       "0             x + y                                     sum of x and y   \n",
       "1             x - y                              difference of x and y   \n",
       "2             x * y                                 product of x and y   \n",
       "3             x / y                                quotient of x and y   \n",
       "4            x // y                        floored quotient of x and y   \n",
       "5             x % y                                 remainder of x / y   \n",
       "6                -x                                          x negated   \n",
       "7                +x                                        x unchanged   \n",
       "8            abs(x)                   absolute value or magnitude of x   \n",
       "9            int(x)                             x converted to integer   \n",
       "10         float(x)                      x converted to floating point   \n",
       "11  complex(re, im)  a complex number with real part re, imaginary ...   \n",
       "12    c.conjugate()                  conjugate of the complex number c   \n",
       "13     divmod(x, y)                           the pair (x // y, x % y)   \n",
       "14        pow(x, y)                                   x to the power y   \n",
       "15           x ** y                                   x to the power y   \n",
       "\n",
       "     Notes Full documentation  \n",
       "0      NaN                NaN  \n",
       "1      NaN                NaN  \n",
       "2      NaN                NaN  \n",
       "3      NaN                NaN  \n",
       "4      (1)                NaN  \n",
       "5      (2)                NaN  \n",
       "6      NaN                NaN  \n",
       "7      NaN                NaN  \n",
       "8      NaN              abs()  \n",
       "9   (3)(6)              int()  \n",
       "10  (4)(6)            float()  \n",
       "11     (6)          complex()  \n",
       "12     NaN                NaN  \n",
       "13     (2)           divmod()  \n",
       "14     (5)              pow()  \n",
       "15     (5)                NaN  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"https://docs.python.org/3.8/library/stdtypes.html#numeric-types-int-float-complex\")[2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "677f596c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17//4 #取整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "dffb3eca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17%5 #取余数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f2365dd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5**2 #5的平方"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0e7e55d",
   "metadata": {},
   "source": [
    "### 3.2 数值的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "ce4a82cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\\x00'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1024).to_bytes(10, byteorder='big') ##bytes 类型的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "f89c718b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(2.0).is_integer()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b5fd92e",
   "metadata": {},
   "source": [
    "## 4.字符串\n",
    "* 课后：\n",
    "> 1. 什么是字符串\n",
    "> 2. 字符串的一般表现形式\n",
    "> 3. 字符串的运算有哪些    +是什么意思\n",
    "> 4. 字符串的一般方法    count(),in"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa1d7dfe",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
